﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiCustomizeColumnsWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands;

public class CUiCustomizeColumnsWindow : TxWindow, IComponentConnector
{
  private CApPropertiesManager _propertiesManager;
  internal Label label1;
  internal Label label2;
  internal ListBox _listBoxAllFields;
  internal ListBox _listBoxSelectedFields;
  internal Button _buttonMoveToRight;
  internal Button _buttonMoveToLeft;
  internal Button _buttonMoveAllToRight;
  internal Button _buttonMoveAllToLeft;
  internal Button _buttonMoveUp;
  internal Button _buttonMoveDown;
  internal Button _buttonCancel;
  internal Button _buttonOK;
  private bool _contentLoaded;

  public CUiCustomizeColumnsWindow(CApPropertiesManager propertiesManager)
  {
    this._propertiesManager = propertiesManager;
    this.InitializeComponent();
  }

  protected virtual void OnInitialized(EventArgs e)
  {
    base.OnInitialized(e);
    foreach (CUiTCObjectProperty unselectedProperty in this._propertiesManager.UnselectedProperties)
    {
      if (unselectedProperty.Name != CApPropertiesManager.BOM_LINE_NAME_PROPERTY)
        this._listBoxAllFields.Items.Add((object) unselectedProperty);
    }
    foreach (CUiTCObjectProperty selectedProperty in this._propertiesManager.SelectedProperties)
    {
      if (selectedProperty.Name != CApPropertiesManager.BOM_LINE_NAME_PROPERTY)
        this._listBoxSelectedFields.Items.Add((object) selectedProperty);
    }
    this.UpdateButtonsStates();
  }

  private void _buttonOK_Click(object sender, RoutedEventArgs e)
  {
    this._propertiesManager.SelectedProperties = (IEnumerable<CUiTCObjectProperty>) new List<CUiTCObjectProperty>(this._listBoxSelectedFields.Items.OfType<CUiTCObjectProperty>());
    ((Window) this).DialogResult = new bool?(true);
    ((Window) this).Close();
  }

  private void _buttonMoveToRight_Click(object sender, RoutedEventArgs e)
  {
    foreach (CUiTCObjectProperty tcObjectProperty in new List<CUiTCObjectProperty>(this._listBoxAllFields.SelectedItems.OfType<CUiTCObjectProperty>()))
    {
      this._listBoxSelectedFields.Items.Add((object) tcObjectProperty);
      this._listBoxAllFields.Items.Remove((object) tcObjectProperty);
    }
  }

  private void _buttonMoveToLeft_Click(object sender, RoutedEventArgs e)
  {
    foreach (CUiTCObjectProperty tcObjectProperty in new List<CUiTCObjectProperty>(this._listBoxSelectedFields.SelectedItems.OfType<CUiTCObjectProperty>()))
    {
      this._listBoxAllFields.Items.Add((object) tcObjectProperty);
      this._listBoxSelectedFields.Items.Remove((object) tcObjectProperty);
    }
  }

  private void _buttonMoveAllToRight_Click(object sender, RoutedEventArgs e)
  {
    foreach (CUiTCObjectProperty newItem in (IEnumerable) this._listBoxAllFields.Items)
      this._listBoxSelectedFields.Items.Add((object) newItem);
    this._listBoxAllFields.Items.Clear();
    this.UpdateButtonsStates();
  }

  private void _buttonMoveAllToLeft_Click(object sender, RoutedEventArgs e)
  {
    foreach (CUiTCObjectProperty newItem in (IEnumerable) this._listBoxSelectedFields.Items)
      this._listBoxAllFields.Items.Add((object) newItem);
    this._listBoxSelectedFields.Items.Clear();
    this.UpdateButtonsStates();
  }

  private void _buttonMoveUp_Click(object sender, RoutedEventArgs e)
  {
    this._listBoxSelectedFields.Focus();
    if (this._listBoxSelectedFields.SelectedItem == null || this._listBoxSelectedFields.SelectedIndex < 1)
      return;
    CUiTCObjectProperty selectedItem = this._listBoxSelectedFields.SelectedItem as CUiTCObjectProperty;
    int insertIndex = this._listBoxSelectedFields.SelectedIndex - 1;
    this._listBoxSelectedFields.Items.Remove((object) selectedItem);
    this._listBoxSelectedFields.Items.Insert(insertIndex, (object) selectedItem);
    this._listBoxSelectedFields.SelectedIndex = insertIndex;
    this.UpdateButtonsStates();
  }

  private void _buttonMoveDown_Click(object sender, RoutedEventArgs e)
  {
    this._listBoxSelectedFields.Focus();
    if (this._listBoxSelectedFields.SelectedItem == null || this._listBoxSelectedFields.SelectedIndex == -1 || this._listBoxSelectedFields.SelectedIndex >= this._listBoxSelectedFields.Items.Count - 1)
      return;
    CUiTCObjectProperty selectedItem = this._listBoxSelectedFields.SelectedItem as CUiTCObjectProperty;
    int insertIndex = this._listBoxSelectedFields.SelectedIndex + 1;
    this._listBoxSelectedFields.Items.Remove((object) selectedItem);
    this._listBoxSelectedFields.Items.Insert(insertIndex, (object) selectedItem);
    this._listBoxSelectedFields.SelectedIndex = insertIndex;
    this.UpdateButtonsStates();
  }

  private void UpdateButtonsStates()
  {
    if (this._listBoxAllFields.Items.Count == 0)
      this._buttonMoveAllToRight.IsEnabled = false;
    else
      this._buttonMoveAllToRight.IsEnabled = true;
    if (this._listBoxSelectedFields.Items.Count == 0)
      this._buttonMoveAllToLeft.IsEnabled = false;
    else
      this._buttonMoveAllToLeft.IsEnabled = true;
    if (this._listBoxAllFields.Items.Count == 0 || this._listBoxAllFields.SelectedItems.Count == 0)
      this._buttonMoveToRight.IsEnabled = false;
    else
      this._buttonMoveToRight.IsEnabled = true;
    if (this._listBoxSelectedFields.Items.Count == 0 || this._listBoxSelectedFields.SelectedItems.Count == 0)
      this._buttonMoveToLeft.IsEnabled = false;
    else
      this._buttonMoveToLeft.IsEnabled = true;
    if (this._listBoxSelectedFields.SelectedItem != null)
    {
      if (this._listBoxSelectedFields.SelectedIndex > 0)
        this._buttonMoveUp.IsEnabled = true;
      else
        this._buttonMoveUp.IsEnabled = false;
      if (this._listBoxSelectedFields.SelectedIndex < this._listBoxSelectedFields.Items.Count - 1)
        this._buttonMoveDown.IsEnabled = true;
      else
        this._buttonMoveDown.IsEnabled = false;
    }
    else
    {
      this._buttonMoveUp.IsEnabled = false;
      this._buttonMoveDown.IsEnabled = false;
    }
  }

  private void _listBoxAllFields_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    this.UpdateButtonsStates();
  }

  private void _listBoxSelectedFields_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    this.UpdateButtonsStates();
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/assigndatafromtc/cuicustomizecolumnswindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.label1 = (Label) target;
        break;
      case 2:
        this.label2 = (Label) target;
        break;
      case 3:
        this._listBoxAllFields = (ListBox) target;
        this._listBoxAllFields.SelectionChanged += new SelectionChangedEventHandler(this._listBoxAllFields_SelectionChanged);
        break;
      case 4:
        this._listBoxSelectedFields = (ListBox) target;
        this._listBoxSelectedFields.SelectionChanged += new SelectionChangedEventHandler(this._listBoxSelectedFields_SelectionChanged);
        break;
      case 5:
        this._buttonMoveToRight = (Button) target;
        this._buttonMoveToRight.Click += new RoutedEventHandler(this._buttonMoveToRight_Click);
        break;
      case 6:
        this._buttonMoveToLeft = (Button) target;
        this._buttonMoveToLeft.Click += new RoutedEventHandler(this._buttonMoveToLeft_Click);
        break;
      case 7:
        this._buttonMoveAllToRight = (Button) target;
        this._buttonMoveAllToRight.Click += new RoutedEventHandler(this._buttonMoveAllToRight_Click);
        break;
      case 8:
        this._buttonMoveAllToLeft = (Button) target;
        this._buttonMoveAllToLeft.Click += new RoutedEventHandler(this._buttonMoveAllToLeft_Click);
        break;
      case 9:
        this._buttonMoveUp = (Button) target;
        this._buttonMoveUp.Click += new RoutedEventHandler(this._buttonMoveUp_Click);
        break;
      case 10:
        this._buttonMoveDown = (Button) target;
        this._buttonMoveDown.Click += new RoutedEventHandler(this._buttonMoveDown_Click);
        break;
      case 11:
        this._buttonCancel = (Button) target;
        break;
      case 12:
        this._buttonOK = (Button) target;
        this._buttonOK.Click += new RoutedEventHandler(this._buttonOK_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
